<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function myWebSocket(url,params){
            return new Promise((resolve,reject)=>{
                 const socket=new WebSocket(url)
                 socket.opnpen=()=>{
                    console.log('建立连接')
                   socket.end(JSON.stringify(params))
                 }
            })
        }
      myWebSocket('ws://localhost:3000',{age:18}).then(res=>{
        console.log(res)
      })

    </script>
</body>
</html>